package com.gxa.modules.communityManagement.controller;

import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.communityManagement.entity.HousingManagement;
import com.gxa.modules.communityManagement.entity.StorageRoomManagement;
import com.gxa.modules.communityManagement.form.HousingManagementForm;
import com.gxa.modules.communityManagement.form.StorageRoomManagementForm;
import com.gxa.modules.communityManagement.service.HousingManagementService;
import com.gxa.modules.communityManagement.service.StorageRoomManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "储物室管理接口")
@RestController
@Slf4j
public class StorageRoomManagementController {
    @Autowired
    private StorageRoomManagementService storageRoomManagementService;

    @ApiOperation(value="储物室管理查询接口")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query",name = "page",value ="当前是第几页",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "limit",value ="每页显示多少条",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "communityId",value ="查询条件-小区ID",dataType ="int"),
            @ApiImplicitParam(paramType = "query",name = "storageRoom",value ="查询条件-储物室号",dataType ="String"),

    }
    )

    @GetMapping("/storageRoomManagement/list")
    public Result<PageUtils> list(@RequestParam Map<String,Object> params){
        log.info("----params-----{}----",params);
        PageUtils pageUtils = this.storageRoomManagementService.queryByPage(params);
        return new Result<PageUtils>().ok(pageUtils);
    }

    @ApiOperation(value="储物室管理添加接口")
    @PostMapping("/storageRoomManagement/add")
    public Result add(@RequestBody StorageRoomManagementForm storageRoomManagementForm){
        log.info("----body-----{}----",storageRoomManagementForm);
        StorageRoomManagement housingManagement=new StorageRoomManagement(storageRoomManagementForm);
        this.storageRoomManagementService.save(housingManagement);
        return new Result().ok();
    }

    @ApiOperation(value="储物室管理删除接口")
    @DeleteMapping ("/storageRoomManagement/delete")
    public Result delete(@RequestBody List<Integer> ids){
        log.info("----param-----{}----",ids);
        this.storageRoomManagementService.removeByIds(ids);
        return new Result().ok();
    }

    @ApiOperation(value="储物室管理修改接口")
    @PutMapping ("/storageRoomManagement/update")
    public Result update(@RequestBody StorageRoomManagementForm storageRoomManagementForm){
        log.info("----param-----{}----",storageRoomManagementForm);
        StorageRoomManagement housingManagement=new StorageRoomManagement(storageRoomManagementForm);
        this.storageRoomManagementService.updateById(housingManagement);
        return new Result().ok();
    }

}
